from collections import Iterable

arr = {"a":"1","b":"2","c":3}
def main ():
    for i,v in arr.items() :
        print(i,v)


arr2 = [1,2,3,4,5,6]
def main2():
    for i,v in enumerate(arr2):
        print(i,v)

arr3 = [(1,"$"),(3,5),(6,8)]
def main3() :
    for x,y in arr3 :
        print(x,y)


main() 
print("-----------------------------------------------")
main2() 
print("-----------------------------------------------")
main3() 
print("-----------------------------------------------")
#判断一个对象是可迭代对象
print(isinstance(arr,Iterable)) #True
print(isinstance(arr2,Iterable)) #True
print(isinstance("arr2",Iterable)) #True
print(isinstance(1234,Iterable)) #False
print("-----------------------------------------------")


#练习 使用迭代查找一个list中最小和最大值，并返回一个tuple
sList = [99,2,54,68,88,3,5,6]

def test(myList) :
    myMax = myList[0]
    myMin = myList[0]
    for i in myList:
        if i > myMax :
            myMax = i
        elif i < myMin :
            myMin = i
    myTuple = (myMin,myMax)
    return myTuple

print(test(sList))

print([x * y for x,y in [(1,2),(4,4)]]) 
#练习 列表生成器,如果list中既包含字符串，又包含整数，由于非字符串类型没有lower()方法，所以列表生成式会报错
L = ['Hello', 'World', 18, 'Apple', None]
def test2(myList) :
    # newList = [x.lower() if isinstance(x,str) else x for x in myList ]
    newList = [x.lower() for x in myList if isinstance(x,str)]
    return newList

print(test2(L))